﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserControl : MonoBehaviour {

	public Sprite LaserOn;//激光打开图片
	public Sprite LaserOff;//激光关闭图片
    public float ChangInterval = 0.5f;//图片切换间隔
	private SpriteRenderer ren;
	private bool isLaserOn=false;
	// Use this for initialization
	void Start () {
		ren= GetComponent<SpriteRenderer>();
		StartCoroutine("ChangeLaserSprite");
	}
	
	// Update is called once per frame
	void Update () {
		//第一种
		
	}
	//携程
	IEnumerator ChangeLaserSprite()
	{
		while (true)
		{
			yield return new WaitForSeconds(ChangInterval);
            //if (isLaserOn)
            //{
            //	ren.sprite=LaserOff;
            //	isLaserOn=true;
            //}
            //else
            //{
            //	ren.sprite = LaserOn;
            //	isLaserOn=false;
            //}

            //if (isLaserOn)
            //{
            //    ren.sprite = LaserOn;
            //}
            //else
            //{
            //    ren.sprite = LaserOff;
            //}

			//正确
            ren.sprite = isLaserOn ? LaserOn : LaserOff;
            isLaserOn = !isLaserOn;


           // Debug.Log("换图了....");
		}
	}
}
